package
{
	import flash.geom.Vector3D;

	public class GameObject implements IRenderable
	{
		private var m_position:Vector3D;
		private var m_display:ISprite;
		
		private var m_destination:Vector3D;
		private var m_distanceLeft:Number;
		
		public function GameObject()
		{
			m_display = Globals.rendererFactory.getSprite(SpriteUtil.getRect(5,5));
		}
		
		public function setDisplayPosition(x:Number, y:Number):void{
			m_display.x = x;
			m_display.y = y;
		}
		
		public function getPosition():Vector3D{
			return m_position;
		}
		
		public function setPosition(pos:Vector3D):void{
			m_position = pos;
		}
		
		public function setParent(parent:IScene):void{
			parent.addToScene(m_display);
		}
		
		public function update():void{
			if(m_destination == null || m_distanceLeft <= 0){
				m_destination = new Vector3D(Math.floor(Math.random()*10),Math.floor(Math.random()*10),0);
				m_distanceLeft = m_position.subtract(m_destination).length;
			}
			var delta:Vector3D = m_destination.subtract(m_position);
			delta.normalize();
			delta.scaleBy(.05);
			
			m_distanceLeft -= delta.length;
			
			m_position = m_position.add(delta);
		}
	}
}